def permute(nums):
    """
    :type nums: List[int]
    :rtype: List[List[int]]
    """
    res = []
    backtracking(nums, res, [])
    return res


def backtracking(nums, res, subset):
    if len(subset) == len(nums):
        res.append(subset.copy())
        return
    for i in range(len(nums)):
        if nums[i] not in subset:
            subset.append(nums[i])
            backtracking(nums, res, subset)
            subset.pop()


nums = [1, 2, 3]
print(permute(nums))  # [[1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], [3, 2, 1]]
